package com.ve.clexer;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main(String[] args) {

        long time, current = System.currentTimeMillis();
        time = current;
        String string;
        try {
            string = FileUtils.readFileToString(new File("D:\\Development\\Project_AndroidStudio\\C51\\app\\src\\main\\assets\\ltest.c"));
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }
        current = System.currentTimeMillis();
        System.out.printf("文本内容读取耗时 %d ms\n", current - time);
        System.out.printf("文本内容字符数 %d \n", string.length());
        time = current;

        WordBuffer wordBuffer = new WordBuffer();
        List<Word> words = new ArrayList<>();

        CharSequence content = string;
        int index = 0;
        int row = 1;
        char c;
        for (index = 0; index < content.length(); ++index) {

            c = content.charAt(index);

            if (c == CLanguage.NEWLINE) {
                row++;
            }
            Word word = wordBuffer.analyse(index, row, c);
            if (word != null) {
                words.add(word);
            }
        }

        current = System.currentTimeMillis();
        System.out.printf("词法分析耗时 %d ms\n", current - time);
        for (Word word : words) {
            System.out.println(word);
        }

    }
}
